package com.elevatorbus.banshou.mina;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

import com.wrench.elevator.base.controller.AppController;
import com.wrench.elevator.util.WrenchUtil;

public class FileUploadHandler extends IoHandlerAdapter
{
    
    
    private static final Log log = LogFactory.getLog(FileUploadHandler.class);
    
    public void sessionOpened(IoSession session)
        throws Exception
    {
       
        System.out.println("server open");
    }
    
    public void exceptionCaught(IoSession session, Throwable cause)
        throws Exception
    {
        System.out.println("exception");
        session.close(true);
        super.exceptionCaught(session, cause);
    }
    
    public void messageReceived(IoSession session, Object message)
    {
        
        if (message instanceof FileUploadRequest)
        {
            FileUploadRequest request = (FileUploadRequest)message;
            log.debug("*************************************************************************************************************************************request:"
                + request);
            WrenchUtil.cacheFileUploadRequest(request);
            
        }
        
    }
    
    public void sessionClosed(IoSession session)
        throws Exception
    {
        System.out.println("server session close");
    }
}